package com.glsc.ngateway.common.base.utils;


import java.util.UUID;


/**
 * @Title: DelTagsUtils
 * @Description: 删除文本中标签
 * @author: 张宁
 * @version: 1.0.0
 * @date: 2020/12/21 16:29
 */

public class DelTagsUtils {


    public static String delHtmlTags(String htmlStr) {
        String scriptRegex = "<script[^>]*?>[\\s\\S]*?<\\/script>";


        String styleRegex = "<style[^>]*?>[\\s\\S]*?<\\/style>";
        //定义HTML标签的正则表达式，去除标签，只提取文字内容
        String htmlRegex = "<[^>]+>";
        //定义空格,回车,换行符,制表符
        String spaceRegex = "\\s*|\t|\r|\n";

        String spaceHtml = "&nbsp";
        // 过滤script标签
        htmlStr = htmlStr.replaceAll(scriptRegex, "");
        // 过滤style标签
        htmlStr = htmlStr.replaceAll(styleRegex, "");
        // 过滤html标签
        htmlStr = htmlStr.replaceAll(htmlRegex, "");
        // 过滤空格等
        htmlStr = htmlStr.replaceAll(spaceRegex, "");
        htmlStr = htmlStr.replaceAll(spaceHtml, "");
        return htmlStr.trim(); // 返回文本字符串
    }


    public static String renameToUUID(String fileName) {
        return UUID.randomUUID() + "." + fileName.substring(fileName.lastIndexOf(".") + 1);
    }


    public static void main(String[] args) {

        String test = null;
        String result = DelTagsUtils.delHtmlTags(test);

        System.out.println(result);

    }


}

